import { Injectable } from '@nestjs/common';
import { createTypesDto, updateTypesDto } from './types.dto';
import { PrismaService } from '../../../prisma/prisma.server';

@Injectable()
export class HouseTypesService {
  constructor(private readonly prisma: PrismaService) {}
  createType({ name, desc }: createTypesDto) {
    return this.prisma.houseTypes.createMany({
      data: {
        typeName: name,
        description: desc,
      },
    });
  }

  getTypes() {
    return this.prisma.houseTypes.findMany();
  }

  updateTypes({ id, name, desc }: updateTypesDto) {
    const data = desc
      ? { typeName: name, description: desc }
      : { typeName: name };
    return this.prisma.houseTypes.updateMany({ where: { id }, data });
  }

  deleteTypes(id: number) {
    return this.prisma.houseTypes.deleteMany({ where: { id } });
  }
}
